//
//  HXInformViewController.m
//  KD
//
//  Created by Hubery on 16/1/29.
//  Copyright © 2016年 ifly. All rights reserved.
//

#import "HXInformViewController.h"
#import "HXSearchBar.h"
#import "HXInformTableViewCell.h"
#import "HXDropdownMenu.h"
#import "HXNewNotify.h"
#import "HXSendNotifyViewController.h"
#import "HXUpDataImageModel.h"
#import "HXSendCommonNotifyViewController.h"
#import "HXNotifyDetailsViewController.h"
#import "HXMeetingNotifyDetailsViewController.h"
#import "HXHomeRecMessageCountModel.h"
#import "HXTabBarViewController.h"
#import "HXNavigationController.h"
#import "HXJobRecordTableViewController.h"

@interface HXInformViewController ()<UITableViewDataSource,UITableViewDelegate,HXNewNotifyDelegate,UIAlertViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) UIView *maskView;
@property(nonatomic,weak) UIButton *receiverBtn;//收件btn
@property(nonatomic,weak) UIButton *sendBtn;//发件btn
/**消息通知页数 分别保存三个数组的页数*/
@property(nonatomic,assign) NSInteger manageSendPage;
@property(nonatomic,assign) NSInteger manageGetPage;
@property(nonatomic,assign) NSInteger corpPage;
@property(nonatomic,assign) HomeNotifyType  status;//1 是发 2是收 3是企业   确定当前是什么状态
@property(nonatomic,strong) NSMutableArray<HXInformListResultModel *> *dataArray;
@property(nonatomic,strong) NSMutableArray<HXInformListResultModel *> *manageSendArray;
@property(nonatomic,strong) NSMutableArray<HXInformListResultModel *> *manageGetArray;
@property(nonatomic,strong) NSMutableArray<HXInformListResultModel *> *corpArray;

@property (nonatomic,assign)  BOOL isbool;
@end

@implementation HXInformViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupTableViewRefresh];
    [self userLogin];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(jpushMessage) name:nMessage object:nil];
    [self jobRecord];
    _isbool = YES;
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self getRECMessageCount];
}

/**周报提醒*/
-(void)jobRecord{
    if ([GlobalUtil isNilValue:[UserDefaultHandler getUserDetault:kID]]) return;
    if (!([[UserDefaultHandler getUserDetault:kUsers_Kind] integerValue] == UserTypeManage)) return;
    [NetworkAPI getJobRecordNotFinishSuccess:^(HXBaseModel *result) {
        if ([result.code isEqualToString:@"201"]) {
            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:result.msg delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            [alert show];
        }else{
            
        }
    } failure:^(NSError *err) {
        
    }];
}

#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex==1) {
        UIWindow *win = [[UIApplication sharedApplication].delegate window];
        HXTabBarViewController *tabVc = (HXTabBarViewController *)win.rootViewController;
        tabVc.selectedIndex = 1;
        HXNavigationController *naVc = tabVc.childViewControllers[1];
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Apply" bundle:nil];
        HXJobRecordTableViewController *meVc = [sb instantiateViewControllerWithIdentifier:@"HXJobRecordTableViewController"];
        [naVc pushViewController:meVc animated:YES];
    }
}

-(void)getRECMessageCount{
    [NetworkAPI getHomeRecMessageCountSuccess:^(HXHomeRecMessageCountModel *result) {
        if ([result.code isEqualToString:@"200"]) {
            if ([result.count integerValue] == 0) {
                self.navigationController.tabBarItem.badgeValue = nil;
            }else{
                self.navigationController.tabBarItem.badgeValue = result.count;
            }
        }
    } failure:^(NSError *err) {
        
    }];
}

//给其他类调用
-(void)actionRefreshData{
//    [self.tableView.mj_header beginRefreshing];
    UIButton *btn = [[UIButton alloc]init];
    btn.tag = 1002;
    [self switchBtnClick:btn];
}

-(void)jpushMessage{
    if ([[UserDefaultHandler getUserDetault:kUsers_Kind] integerValue] == UserTypeManage) {
        self.receiverBtn.selected = YES;
        self.receiverBtn.backgroundColor = MAINCOLOR;
        self.sendBtn.backgroundColor = [UIColor whiteColor];
        self.sendBtn.selected = NO;
        self.status = HomeNotifyTypeManageGet;
    }else if([[UserDefaultHandler getUserDetault:kUsers_Kind] integerValue] == UserTypeCorp){
        self.status = HomeNotifyTypeCorpGet;
    }else{
        self.status = HomeNotifyTypeManageGet;
    }
    [self.tableView.mj_header beginRefreshing];
}

-(void)loginJPush{
    if (![[UserDefaultHandler getUserDetault:kIsLoginJpush] isEqualToString:@"yes"]) {//没有登陆过
//        [self loginJPushUser:[UserDefaultHandler getUserDetault:kUsers_Alias] pwd:[UserDefaultHandler getUserDetault:kUsers_PassWord]];
    }
}

//设置别名
- (void)setBieName:(NSString *)userName pwd:(NSString *)pwd {
   
    [JPUSHService setTags:[[NSSet alloc] init] alias:userName fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) {
        NSLog(@"********************* \n\nrescode: %d, \ntags: %@, \nalias: %@\n***********************\n", iResCode, iTags , iAlias);
        if (iResCode == 0) {
            [UserDefaultHandler saveUserDetault:@"yes" key:kIResCodeIs0Jpush];
            _isbool = NO;
        }else{
            if (_isbool) {
                
                [self setBieName:userName pwd:pwd];
            }
        }
    }];
}
// 登录极光
-(void)loginJPushUser:(NSString *)userName pwd:(NSString *)pwd{
    [JMSGUser loginWithUsername:userName
                       password:pwd
              completionHandler:^(id resultObject, NSError *error) {
                  if (error == nil) {
                      [UserDefaultHandler saveUserDetault:@"yes" key:kIsLoginJpush];//登录成功
                      [UserDefaultHandler saveUserDetault:@"yes" key:kIsRegisterJpush];//注册成功
                      [self setBieName:userName pwd:pwd];
                  } else {
                      
                  }
              }];
}

-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

-(void)setBarView{
    UIButton *receiverBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    receiverBtn.tag = 1001;
    [receiverBtn setTitle:@"收件箱" forState:UIControlStateNormal];
    [receiverBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [receiverBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [receiverBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [receiverBtn setBackgroundColor:MAINCOLOR];
    receiverBtn.titleLabel.font = [UIFont boldSystemFontOfSize:13];
    [receiverBtn setFrame:CGRectMake(0, 0, 65, 25)];
    [receiverBtn addTarget:self action:@selector(switchBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *sendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    sendBtn.tag = 1002;
    [sendBtn setTitle:@"发件箱" forState:UIControlStateNormal];
    [sendBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [sendBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [sendBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [sendBtn setBackgroundColor:[UIColor whiteColor]];
    sendBtn.titleLabel.font = [UIFont boldSystemFontOfSize:13];
    [sendBtn setFrame:CGRectMake(65, 0, 65, 25)];
    [sendBtn addTarget:self action:@selector(switchBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *view = [[UIView alloc]init];
    [view addSubview:receiverBtn];
    [view addSubview:sendBtn];
    view.layer.borderWidth = 1;
    view.layer.borderColor = MAINCOLOR.CGColor;
    view.layer.cornerRadius = 3;
    view.layer.masksToBounds = YES;
    self.receiverBtn = receiverBtn;
    self.sendBtn = sendBtn;
    view.frame = CGRectMake(0, 0, 130, 25);
    self.navigationItem.titleView = view;
    receiverBtn.selected = YES;
}

/**顶部两个按钮点击事件*/
-(void)switchBtnClick:(UIButton*)btn{
    [self.tableView.mj_footer resetNoMoreData];
    [self.tableView.mj_footer setAlpha:0];
    if (btn.tag == 1001) {//收件箱
        self.receiverBtn.selected = YES;
        self.receiverBtn.backgroundColor = MAINCOLOR;
        self.sendBtn.backgroundColor = [UIColor whiteColor];
        self.status = HomeNotifyTypeManageGet;
        self.sendBtn.selected = NO;
        self.dataArray = self.manageGetArray;
        [self.tableView reloadData];
    }else if(btn.tag == 1002){//发件箱
        self.receiverBtn.selected = NO;
        self.sendBtn.selected = YES;
        self.receiverBtn.backgroundColor = [UIColor whiteColor];
        self.status = HomeNotifyTypeManageSend;
        self.sendBtn.backgroundColor = MAINCOLOR;
        self.dataArray = self.manageSendArray;
        [self.tableView reloadData];
    }else{
        NSAssert(0, @"主界面btn选则崩溃");
    }
    [self.tableView.mj_header beginRefreshing];
}

//发通知
- (void)btnClick:(NSInteger)type{
    if (type == NotifyTypeMeeting) {//会议通知
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"HXInform" bundle:nil];
        HXSendNotifyViewController *vc = [sb instantiateViewControllerWithIdentifier:@"HXSendNotifyViewController"];
        vc.superVc = self;
        vc.sendType = @"qiye";
        [self.navigationController pushViewController:vc animated:YES];
    }else if (type == NotifyTypeCommon){//主管通知
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"HXInform" bundle:nil];
        HXSendCommonNotifyViewController *vc = [sb instantiateViewControllerWithIdentifier:@"HXSendCommonNotifyViewController"];
        vc.superVc = self;
        [self.navigationController pushViewController:vc animated:YES];
    }else{//主管内部通知
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"HXInform" bundle:nil];
        HXSendNotifyViewController *vc = [sb instantiateViewControllerWithIdentifier:@"HXSendNotifyViewController"];
        vc.superVc = self;
        vc.sendType = @"zhuguan";
        [self.navigationController pushViewController:vc animated:YES];
    }
}

#pragma mark - 监听用户登录的通知方法
//主管才有右上角发通知按钮 和收发件箱
-(void)userLogin{
    //极光登录注册定时器
//    self.timer = [NSTimer timerWithTimeInterval:30.f target:self selector:@selector(loginJPush) userInfo:nil repeats:YES];
//    [[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
    [self loginJPush];

    [self.tableView.mj_footer resetNoMoreData];
    if ([[UserDefaultHandler getUserDetault:kUsers_Kind] integerValue] == UserTypeManage) {//主管
        self.status = HomeNotifyTypeManageGet;//先让界面状态是主管收件箱
        [self setBarView];
        self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImage:@"map_icon_zoom_in" highImage:@"map_icon_zoom_in_high" target:self action:@selector(rightBtnAction:)];
    }else{
        self.status = HomeNotifyTypeCorpGet;
        self.navigationItem.rightBarButtonItem = nil;
        self.navigationItem.titleView = nil;
    }
    [self.tableView.mj_header beginRefreshing];
}

-(void)rightBtnAction:(UIBarButtonItem *)btn{
    HXNewNotify *myview = [[[NSBundle mainBundle] loadNibNamed:@"HXNewNotify" owner:nil options:nil] lastObject];
    myview.delegate = self;
    
    HXDropdownMenu *menu = [HXDropdownMenu menu];
    menu.content = myview;
    [menu showFrom:(UIView *)btn];
}

-(void)setupTableViewRefresh{
    self.manageSendPage = 0;
    self.manageGetPage = 0;
    self.corpPage = 0;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 75;
    self.tableView.tableFooterView = [[UIView alloc]init];
    [self.tableView registerNib:[UINib nibWithNibName:@"HXInformTableViewCell" bundle:nil] forCellReuseIdentifier:@"HXInformTableViewCell"];
    
    //刷新控件
    self.tableView.mj_header=[AWRefreshHeader headerWithRefreshingTarget:self refreshingAction:@selector(refreshData)];
    self.tableView.mj_footer=[AWRefreshFooder footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    self.tableView.mj_footer.automaticallyChangeAlpha = YES;
    self.tableView.mj_footer.automaticallyHidden = NO;
    [self.tableView.mj_header beginRefreshing];
}
//-(void)viewWillAppear:(BOOL)animated {
//    [super viewWillAppear:YES];
//    [self refreshData];
//}


-(void)refreshData{
    [NetworkAPI cancelALlTasks];//取消所有请求
    if(self.tableView.mj_footer.isRefreshing)[self.tableView.mj_footer endRefreshing];
    if (self.status == HomeNotifyTypeCorpGet) {//企业
        self.corpPage = 0;
        [self corpGetData];
    }else if (self.status == HomeNotifyTypeManageGet){//主管收件
        self.manageGetPage = 0;
        [self manageGetData];
    }else if (self.status == HomeNotifyTypeManageSend){//主管发
        self.manageSendPage = 0;
        [self manageSendData];
    }
}


-(void)loadMoreData{
    [NetworkAPI cancelALlTasks];//取消所有请求
    if(self.tableView.mj_header.isRefreshing)[self.tableView.mj_header endRefreshing];
    if (self.status == HomeNotifyTypeCorpGet) {//企业
        [self moreCorpGetData];
    }else if (self.status == HomeNotifyTypeManageGet){//主管收件
        [self moreManageGetData];
    }else if (self.status == HomeNotifyTypeManageSend){//主管发
        [self moreManageSendData];
    }
}

-(void)manageSendData{
    [NetworkAPI notifyManageSendListWithTitle:@""
                                       userId:[UserDefaultHandler getUserDetault:kID]
                                     userKind:[UserDefaultHandler getUserDetault:kUsers_Kind]
                                      pageNum:[NSString stringWithFormat:@"%ld",(long)self.manageSendPage]
                                      success:^(HXInformListModel *result) {
                                                                          if ([result.code isEqualToString:@"200"]) {
                                                                              [SVProgressHUD showSuccessWithStatus:@"获取通知成功"];
                                                                              [self.tableView.mj_header endRefreshing];
                                                                              self.manageSendPage++;
                                                                              [self.manageSendArray removeAllObjects];
                                                                              [self.manageSendArray addObjectsFromArray:result.msglist];
                                                                              self.dataArray = self.manageSendArray;
                                                                              [self.tableView reloadData];
                                                                              if ([result.msglist count] < 10) {
                                                                                  [self.tableView.mj_footer endRefreshingWithNoMoreData];
                                                                                  self.tableView.mj_footer.alpha = 1.0f;
                                                                                  return;
                                                                              }
                                                                          }else if([result.code isEqualToString:@"400"]){
                                                                                [self.tableView.mj_header endRefreshing];
                                                                                [self.tableView.mj_footer endRefreshingWithNoMoreData];
                                                                                self.tableView.mj_footer.alpha = 1.0f;
                                                                          }else{
                                                                              [SVProgressHUD showErrorWithStatus:@"网络错误"];
                                                                              [self.tableView.mj_header endRefreshing];
                                                                          }
                                                                      } failure:^(NSError *err) {
                                                                          [self.tableView.mj_header endRefreshing];
                                                                      }];
}

-(void)moreManageSendData{
    [NetworkAPI notifyManageSendListWithTitle:@""
                                       userId:[UserDefaultHandler getUserDetault:kID]
                                     userKind:[UserDefaultHandler getUserDetault:kUsers_Kind]
                                      pageNum:[NSString stringWithFormat:@"%ld",(long)self.manageSendPage]
                                      success:^(HXInformListModel *result) {
                                                                          if ([result.code isEqualToString:@"200"]) {
                                                                              if ([result.msglist count] == 0) {//如果没有数据了
                                                                                  [self.tableView.mj_footer endRefreshingWithNoMoreData];
                                                                                  self.tableView.mj_footer.alpha = 1.0f;
                                                                                  return;
                                                                              }else if([result.msglist count] < 10){//有数据但是没有下一页了
                                                                                  [self.manageSendArray addObjectsFromArray:result.msglist];
                                                                                  self.dataArray = self.manageSendArray;
                                                                                  [self.tableView reloadData];
                                                                                  [self.tableView.mj_footer endRefreshingWithNoMoreData];
                                                                                  self.tableView.mj_footer.alpha = 1.0f;
                                                                              }else{//还有更多数据
                                                                                 self.manageSendPage++;
                                                                                 [self.manageSendArray addObjectsFromArray:result.msglist];
                                                                                 self.dataArray = self.manageSendArray;
                                                                                 [self.tableView reloadData];
                                                                                 [self.tableView.mj_footer endRefreshing];
                                                                                 self.tableView.mj_footer.alpha = 0;
                                                                              }
                                                                          }else if([result.code isEqualToString:@"400"]){
                                                                              [self.tableView.mj_header endRefreshing];
                                                                              [self.tableView.mj_footer endRefreshingWithNoMoreData];
                                                                              self.tableView.mj_footer.alpha = 1.0f;
                                                                          }else{
                                                                              [SVProgressHUD showErrorWithStatus:@"网络错误"];
                                                                              [self.tableView.mj_footer endRefreshing];
                                                                          }
                                                                      } failure:^(NSError *err) {
                                                                          [self.tableView.mj_footer endRefreshing];
                                    }];

}

-(void)manageGetData{
    [NetworkAPI notifyManageGetListWithTitle:@""
                                      userId:[UserDefaultHandler getUserDetault:kID]
                                    userKind:[UserDefaultHandler getUserDetault:kUsers_Kind]
                                     pageNum:[NSString stringWithFormat:@"%ld",(long)self.manageGetPage]
                                     success:^(HXInformListModel *result) {
                                         if ([result.code isEqualToString:@"200"]) {
                                             [SVProgressHUD showSuccessWithStatus:@"获取通知成功"];
                                             [self.tableView.mj_header endRefreshing];
                                             self.manageGetPage++;
                                             [self.manageGetArray removeAllObjects];
                                             [self.manageGetArray addObjectsFromArray:result.msglist];
                                             self.dataArray = self.manageGetArray;
                                             [self.tableView reloadData];
                                             if ([result.msglist count] < 10) {
                                                 [self.tableView.mj_footer endRefreshingWithNoMoreData];
                                                 self.tableView.mj_footer.alpha = 1.0f;
                                                 return;
                                             }
                                         }else if([result.code isEqualToString:@"400"]){
                                             [self.tableView.mj_header endRefreshing];
                                             [self.tableView.mj_footer endRefreshingWithNoMoreData];
                                             self.tableView.mj_footer.alpha = 1.0f;
                                         }else{
                                             [SVProgressHUD showErrorWithStatus:@"网络错误"];
                                             [self.tableView.mj_header endRefreshing];
                                         }
                                     } failure:^(NSError *err) {
                                         [self.tableView.mj_header endRefreshing];
                                     }];
}

-(void)moreManageGetData{
    [NetworkAPI notifyManageGetListWithTitle:@""
                                      userId:[UserDefaultHandler getUserDetault:kID]
                                    userKind:[UserDefaultHandler getUserDetault:kUsers_Kind]
                                     pageNum:[NSString stringWithFormat:@"%ld",(long)self.manageGetPage]
                                     success:^(HXInformListModel *result) {
                                         if ([result.code isEqualToString:@"200"]) {
                                             if ([result.msglist count] == 0) {//如果没有数据了
                                                 [self.tableView.mj_footer endRefreshingWithNoMoreData];
                                                 self.tableView.mj_footer.alpha = 1.0f;
                                                 return;
                                             }else if([result.msglist count] < 10){//有数据但是没有下一页了
                                                 [self.manageGetArray addObjectsFromArray:result.msglist];
                                                 self.dataArray = self.manageGetArray;
                                                 [self.tableView reloadData];
                                                 [self.tableView.mj_footer endRefreshingWithNoMoreData];
                                                 self.tableView.mj_footer.alpha = 1.0f;
                                             }else{//还有更多数据
                                                 self.manageGetPage++;
                                                 [self.manageGetArray addObjectsFromArray:result.msglist];
                                                 self.dataArray = self.manageGetArray;
                                                 [self.tableView reloadData];
                                                 [self.tableView.mj_footer endRefreshing];
                                                 self.tableView.mj_footer.alpha = 0;
                                             }
                                         }else if([result.code isEqualToString:@"400"]){
                                             [self.tableView.mj_header endRefreshing];
                                             [self.tableView.mj_footer endRefreshingWithNoMoreData];
                                             self.tableView.mj_footer.alpha = 1.0f;
                                         }else{
                                             [SVProgressHUD showErrorWithStatus:@"网络错误"];
                                             [self.tableView.mj_footer endRefreshing];
                                         }
                                     } failure:^(NSError *err) {
                                         [self.tableView.mj_footer endRefreshing];
                                     }];
}

-(void)corpGetData{
    [NetworkAPI notifyCorpGetListWithTitle:@""
                             userId:[UserDefaultHandler getUserDetault:kID]
                           userKind:[UserDefaultHandler getUserDetault:kUsers_Kind]
                            pageNum:[NSString stringWithFormat:@"%ld",(long)self.corpPage]
                            success:^(HXInformListModel *result) {
                                if ([result.code isEqualToString:@"200"]) {
                                    [SVProgressHUD showSuccessWithStatus:@"获取通知成功"];
                                    [self.tableView.mj_header endRefreshing];
                                    self.corpPage++;
                                    [self.corpArray removeAllObjects];
                                    [self.corpArray addObjectsFromArray:result.msglist];
                                    self.dataArray = self.corpArray;
                                    [self.tableView reloadData];
                                    if ([result.msglist count] < 10) {
                                        [self.tableView.mj_footer endRefreshingWithNoMoreData];
                                        self.tableView.mj_footer.alpha = 1.0f;
                                        return;
                                    }
                                }else if([result.code isEqualToString:@"400"]){
                                    [self.tableView.mj_header endRefreshing];
                                    [self.tableView.mj_footer endRefreshingWithNoMoreData];
                                    self.tableView.mj_footer.alpha = 1.0f;
                                }else{
                                    [SVProgressHUD showErrorWithStatus:@"网络错误"];
                                    [self.tableView.mj_header endRefreshing];
                                }
                            } failure:^(NSError *err) {
                                [self.tableView.mj_header endRefreshing];
                            }];
}


-(void)moreCorpGetData{
    [NetworkAPI notifyCorpGetListWithTitle:@""
                                    userId:[UserDefaultHandler getUserDetault:kID]
                                  userKind:[UserDefaultHandler getUserDetault:kUsers_Kind]
                                   pageNum:[NSString stringWithFormat:@"%ld",(long)self.corpPage]
                                   success:^(HXInformListModel *result) {
                                       if ([result.code isEqualToString:@"200"]) {
                                           if ([result.msglist count] == 0) {//如果没有数据了
                                               [self.tableView.mj_footer endRefreshingWithNoMoreData];
                                               self.tableView.mj_footer.alpha = 1.0f;
                                               return;
                                           }else if([result.msglist count] < 10){//有数据但是没有下一页了
                                               [self.corpArray addObjectsFromArray:result.msglist];
                                               self.dataArray = self.manageGetArray;
                                               [self.tableView reloadData];
                                               [self.tableView.mj_footer endRefreshingWithNoMoreData];
                                               self.tableView.mj_footer.alpha = 1.0f;
                                           }else{//还有更多数据
                                               self.corpPage++;
                                               [self.corpArray addObjectsFromArray:result.msglist];
                                               self.dataArray = self.corpArray;
                                               [self.tableView reloadData];
                                               [self.tableView.mj_footer endRefreshing];
                                               self.tableView.mj_footer.alpha = 0;
                                           }
                                       }else if([result.code isEqualToString:@"400"]){
                                           [self.tableView.mj_header endRefreshing];
                                           [self.tableView.mj_footer endRefreshingWithNoMoreData];
                                           self.tableView.mj_footer.alpha = 1.0f;
                                       }else{
                                           [SVProgressHUD showErrorWithStatus:@"网络错误"];
                                           [self.tableView.mj_footer endRefreshing];
                                       }
                                   } failure:^(NSError *err) {
                                       [self.tableView.mj_footer endRefreshing];
                                   }];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    HXInformTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HXInformTableViewCell" forIndexPath:indexPath];
    cell.data = self.dataArray[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"HXInform" bundle:nil];
    HXInformListResultModel* data = self.dataArray[indexPath.row];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    [dict setObject:data.MessageID forKey:@"data.MessageID"];
    [dict setObject:data.TMUserID forKey:@"data.TMUserID"];
    
    if (([data.TypeCode integerValue] == NotifyTypeManage)){//内部会议
        HXMeetingNotifyDetailsViewController *vc  = [sb instantiateViewControllerWithIdentifier:@"HXMeetingNotifyDetailsViewController"];
        vc.messageDict = dict;
        vc.meetingType = @"neibu";
        if ([data.IsRead isEqualToString:@"0"]) {
            data.IsRead = @"1";
            NSIndexPath *path = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
            [self.tableView reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationRight];
            
        }
        [self.navigationController pushViewController:vc animated:YES];
    }else if(([data.TypeCode integerValue] == NotifyTypeCommon)){//预警
        HXNotifyDetailsViewController *vc  = [sb instantiateViewControllerWithIdentifier:@"HXNotifyDetailsViewController"];
        vc.messageDict = dict;
        if ([data.IsRead isEqualToString:@"0"]) {
            data.IsRead = @"1";
            NSIndexPath *path = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
            [self.tableView reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationRight];
        }
        [self.navigationController pushViewController:vc animated:YES];
    }else{//企业会议 有回执
        HXMeetingNotifyDetailsViewController *vc  = [sb instantiateViewControllerWithIdentifier:@"HXMeetingNotifyDetailsViewController"];
        vc.messageDict = dict;
        vc.meetingType = @"qiye";
        if ([data.IsRead isEqualToString:@"0"]) {
            data.IsRead = @"1";
            NSIndexPath *path = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
            [self.tableView reloadRowsAtIndexPaths:@[path] withRowAnimation:UITableViewRowAnimationRight];
            
        }
        [self.navigationController pushViewController:vc animated:YES];
    }
}

////删除操作
//-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
//    if(editingStyle == UITableViewCellEditingStyleDelete)
//    {
//        HXInformListResultModel *data = self.dataArray[indexPath.row];
//        [SVProgressHUD showWithStatus:@"正在删除" ];
//        [NetworkAPI deleteNotifyWithMessageID:data.MessageID
//                                                    TMUserID:data.TMUserID
//                                                     UserID:data.UserID
//                                                     UserKind:[NSString stringWithFormat:@"%@",[UserDefaultHandler getUserDetault:kUsers_Kind]]
//                                                     success:^(HXBaseModel *result) {
//                                                         if ([result.code isEqualToString:@"200"]) {
//                                                             [SVProgressHUD dismiss];
//                                                             [self.dataArray removeObjectAtIndex:indexPath.row];
//                                                             [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];//动画删除指定的行
//                                                         }else{
//                                                              [SVProgressHUD showErrorWithStatus:@"删除失败"];
//                                                         }
//
//                                                     } failure:^(NSError *err) {
//        [SVProgressHUD showErrorWithStatus:@"删除失败"];
//    }];
//    }
//}

-(NSString*)tableView:(UITableView*)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath*)indexpath {
    return @" 删除";
}

#pragma mark - 懒加载
- (NSMutableArray<HXInformListResultModel *> *)dataArray{
    if (_dataArray == nil) {
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}

- (NSMutableArray<HXInformListResultModel *> *)manageSendArray{
    if (_manageSendArray == nil) {
        _manageSendArray = [[NSMutableArray alloc]init];
    }
    return _manageSendArray;
}

- (NSMutableArray<HXInformListResultModel *> *)manageGetArray{
    if (_manageGetArray == nil) {
        _manageGetArray = [[NSMutableArray alloc]init];
    }
    return _manageGetArray;
}

- (NSMutableArray<HXInformListResultModel *> *)corpArray{
    if (_corpArray == nil) {
        _corpArray = [[NSMutableArray alloc]init];
    }
    return _corpArray;
}

//
//-(void)qiye{
//    //        [MBProgressHUD showMessage:@"正在获取" toView: self.navigationController.view];
//    [NetworkAPI notifyListWithTitle:@""
//                             userId:[UserDefaultHandler getUserDetault:kID]
//                           userKind:[UserDefaultHandler getUserDetault:kUsers_Kind]
//                            pageNum:@"0"
//                            success:^(HXInformListModel *result) {
//                                //                                [MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:YES];
//                                [self.tableView.mj_header endRefreshing];
//                                if ([result.code isEqualToString:@"200"]) {
//                                    self.index++;
//                                    [SVProgressHUD showSuccessWithStatus:@"获取通知成功"];
//                                    [self.dataArray removeAllObjects];
//                                    [self.dataArray addObjectsFromArray:result.msglist];
//                                    [self.tableView reloadData];
//                                    if ([result.msglist count] < 10) {
//                                        [self.tableView.mj_header endRefreshing];
//                                        [self.tableView.mj_footer endRefreshingWithNoMoreData];
//                                        self.tableView.mj_footer.alpha = 1.0f;
//                                        return;
//                                    }
//                                }else if([result.code isEqualToString:@"400"]){
//                                    //                                        [self.tableView.mj_header endRefreshing];
//                                    //                                        [self.tableView.mj_footer endRefreshingWithNoMoreData];
//                                    //                                        self.tableView.mj_footer.alpha = 1.0f;
//                                }else{
//                                    [SVProgressHUD showErrorWithStatus:@"网络错误"];
//                                    //                                        [self.tableView.mj_header endRefreshing];
//                                    //                                [MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:YES];
//                                    //                                        [self.tableView.mj_footer endRefreshing];
//                                }
//                            } failure:^(NSError *err) {
//                                [SVProgressHUD showErrorWithStatus:@"网络错误"];
//                                //                                    [self.tableView.mj_header endRefreshing];
//                                //                                [MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:YES];
//                                //                                    [self.tableView.mj_footer endRefreshing];
//                            }];
//}


//-(void)loadMoreData{
//    [NetworkAPI notifyListWithTitle:@""
//                             userId:[UserDefaultHandler getUserDetault:kID]
//                           userKind:[UserDefaultHandler getUserDetault:kUsers_Kind]
//                            pageNum:[NSString stringWithFormat:@"%ld",(long)self.index]
//                            success:^(HXInformListModel *result) {
//                                if ([result.code isEqualToString:@"200"]) {
//                                    if ([result.msglist count] == 0) {
//                                        [self.tableView.mj_header endRefreshing];
//                                        [self.tableView.mj_footer endRefreshingWithNoMoreData];
//                                        self.tableView.mj_footer.alpha = 1.0f;
//                                        return;
//                                    }
//                                    self.index++;
//                                    [self.dataArray addObjectsFromArray:result.msglist];
//                                    [self.tableView reloadData];
//                                    [self.tableView.mj_footer endRefreshing];
//                                    self.tableView.mj_footer.alpha = 0;
//                                }else if([result.code isEqualToString:@"400"]){
//                                    [self.tableView.mj_header endRefreshing];
//                                    [self.tableView.mj_footer endRefreshingWithNoMoreData];
//                                    self.tableView.mj_footer.alpha = 1.0f;
//                                }else{
//                                    [SVProgressHUD showErrorWithStatus:@"网络错误"];
//                                    [self.tableView.mj_header endRefreshing];
//                                    //                                [MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:YES];
//                                    [self.tableView.mj_footer endRefreshing];
//                                }
//                            } failure:^(NSError *err) {
//                                [SVProgressHUD showErrorWithStatus:@"网络错误"];
//                                [self.tableView.mj_header endRefreshing];
//                                //                                [MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:YES];
//                                [self.tableView.mj_footer endRefreshing];
//                            }];
//}

@end
